﻿#region Licence

// Copyright (C) 2011 by QianFan Jiang 
// This code is based on Jakub Bartkowiak (Gralin)'s NRF24L10Plus [http://nrf24l01.codeplex.com/]
// 
// MIT Licence
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#endregion

using System;
using Microsoft.SPOT;

namespace nRF24L10P
{
    public class SPICommands
    {
        /// <summary>
        ///   Read command and status registers. 
        ///   AAAAA = 5 bit Register Map Address
        ///   Data bytes: 1 to 5 (LSByte first)
        /// </summary>
        public const byte R_REGISTER = 0x00;

        /// <summary>
        ///   Write command and status registers. 
        ///   AAAAA = 5 bit Register Map Address Executable in power down or standby modes only.
        ///   Data bytes: 1 to 5 (LSByte first)
        /// </summary>
        public const byte W_REGISTER = 0x20;

        /// <summary>
        ///   Read RX-payload: 1 – 32 bytes. 
        ///   A read operation always starts at byte 0. 
        ///   Payload is deleted from FIFO after it is read. Used in RX mode.
        ///   Data bytes: 1 to 32 (LSByte first)
        /// </summary>
        public const byte R_RX_PAYLOAD = 0x61;

        /// <summary>
        ///   Write TX-payload: 1 – 32 bytes. 
        ///   A write operation always starts at byte 0 used in TX payload.
        ///   Data bytes: 1 to 32 (LSByte first)
        /// </summary>
        public const byte W_TX_PAYLOAD = 0xA0;

        /// <summary>
        ///   Flush TX FIFO, used in TX mode
        ///   Data bytes: 0
        /// </summary>
        public const byte FLUSH_TX = 0xE1;

        /// <summary>
        ///   Flush RX FIFO, used in RX mode Should not be executed during transmission of acknowledge. 
        ///   Acknowledge package will not be completed.
        ///   Data bytes: 0
        /// </summary>
        public const byte FLUSH_RX = 0xE2;

        /// <summary>
        ///   Used for a PTX device Reuse last transmitted payload. 
        ///   TX payload reuse is active until W_TX_PAYLOAD or FLUSH TX is executed. 
        ///   TX payload reuse must not be activated or deactivated during package transmission.
        ///   Data bytes: 0
        /// </summary>
        public const byte REUSE_TX_PL = 0xE3;

        /// <summary>
        ///   Read RX payload width for the top R_RX_PAYLOAD in the RX FIFO.
        ///   Flush RX FIFO if the read value is larger than 32 bytes.
        ///   Data bytes: 1
        /// </summary>
        public const byte R_RX_PL_WID = 0x60;

        /// <summary>
        ///   Used in RX mode.
        ///   Write Payload to be transmitted together with ACK packet on PIPE PPP.
        ///   PPP valid in the range from 000 to 101.
        ///   Maximum three ACK packet payloads can be pending. 
        ///   Payloads with same PPP are handled using first in - first out principle. 
        ///   Write payload: 1– 32 bytes. 
        ///   A write operation always starts at byte 0.
        ///   Data bytes: 1 to 32 (LSByte first)
        /// </summary>
        public const byte W_ACK_PAYLOAD = 0xA8;

        /// <summary>
        ///   Used in TX mode. Disables AUTOACK on this specific packet.
        ///   Data bytes: 1 to 32 (LSByte first)
        /// </summary>
        public const byte W_TX_PAYLOAD_NO_ACK = 0xB0;

        /// <summary>
        ///   No Operation. Might be used to read the STATUS register
        ///   Data bytes: 0
        /// </summary>
        public const byte NOP = 0xFF;
    }

    public enum FIFOStatusEnum
    {
        Full,
        Empty,
        InUse
    }

    public enum DeviceStatusEnum
    {
        Undefined,
        PowerDown,
        StandBy,
        TXMode,
        RXMode
    }

    //public static class Registers
    //{
    //    /// <summary>
    //    ///   Configuration Register
    //    /// </summary>
    //    public const byte CONFIG = 0x00;

    //    /// <summary>
    //    ///   Enable 'Auto Acknowledgment' Function. Disable this functionality to be compatible with nRF2401.
    //    /// </summary>
    //    public const byte EN_AA = 0x01;

    //    /// <summary>
    //    ///   Enabled RX Addresses
    //    /// </summary>
    //    public const byte EN_RXADDR = 0x02;

    //    /// <summary>
    //    ///   Setup of Address Widths (common for all data pipes)
    //    /// </summary>
    //    public const byte SETUP_AW = 0x03;

    //    /// <summary>
    //    ///   Setup of Automatic Retransmission
    //    /// </summary>
    //    public const byte SETUP_RETR = 0x04;

    //    /// <summary>
    //    ///   RF Channel
    //    /// </summary>
    //    public const byte RF_CH = 0x05;

    //    /// <summary>
    //    ///   RF Setup Register
    //    /// </summary>
    //    public const byte RF_SETUP = 0x06;

    //    /// <summary>
    //    ///   Status Register (In parallel to the SPI command word applied on the MOSI pin, the STATUS register is shifted serially out on the MISO pin)
    //    /// </summary>
    //    public const byte STATUS = 0x07;

    //    /// <summary>
    //    ///   Transmit observe register
    //    /// </summary>
    //    public const byte OBSERVE_TX = 0x08;

    //    /// <summary>
    //    ///   Received Power Detector.
    //    /// </summary>
    //    public const byte RPD = 0x09;

    //    /// <summary>
    //    ///   Receive address data pipe 0. 5 Bytes maximum length. (LSByte is written first. Write the number of bytes defined by SETUP_AW)
    //    /// </summary>
    //    public const byte RX_ADDR_P0 = 0x0A;

    //    /// <summary>
    //    ///   Receive address data pipe 1. 5 Bytes maximum length. (LSByte is written first. Write the number of bytes defined by SETUP_AW)
    //    /// </summary>
    //    public const byte RX_ADDR_P1 = 0x0B;

    //    /// <summary>
    //    ///   Receive address data pipe 2. Only LSB. MSBytes are equal to RX_ADDR_P1
    //    /// </summary>
    //    public const byte RX_ADDR_P2 = 0x0C;

    //    /// <summary>
    //    ///   Receive address data pipe 3. Only LSB. MSBytes are equal to RX_ADDR_P1
    //    /// </summary>
    //    public const byte RX_ADDR_P3 = 0x0D;

    //    /// <summary>
    //    ///   Receive address data pipe 4. Only LSB. MSBytes are equal to RX_ADDR_P1
    //    /// </summary>
    //    public const byte RX_ADDR_P4 = 0x0E;

    //    /// <summary>
    //    ///   Receive address data pipe 5. Only LSB. MSBytes are equal to RX_ADDR_P1
    //    /// </summary>
    //    public const byte RX_ADDR_P5 = 0x0F;

    //    /// <summary>
    //    ///   Transmit address. Used for a PTX device only. (LSByte is written first) 
    //    ///   Set RX_ADDR_P0 equal to this address to handle automatic acknowledge if this is a PTX device with Enhanced ShockBurst™ enabled.
    //    /// </summary>
    //    public const byte TX_ADDR = 0x10;

    //    /// <summary>
    //    ///   Number of bytes in RX payload in data pipe 0
    //    /// </summary>
    //    public const byte RX_PW_P0 = 0x11;

    //    /// <summary>
    //    ///   Number of bytes in RX payload in data pipe 1
    //    /// </summary>
    //    public const byte RX_PW_P1 = 0x12;

    //    /// <summary>
    //    ///   Number of bytes in RX payload in data pipe 2
    //    /// </summary>
    //    public const byte RX_PW_P2 = 0x13;

    //    /// <summary>
    //    ///   Number of bytes in RX payload in data pipe 3
    //    /// </summary>
    //    public const byte RX_PW_P3 = 0x14;

    //    /// <summary>
    //    ///   Number of bytes in RX payload in data pipe 4
    //    /// </summary>
    //    public const byte RX_PW_P4 = 0x15;

    //    /// <summary>
    //    ///   Number of bytes in RX payload in data pipe 5
    //    /// </summary>
    //    public const byte RX_PW_P5 = 0x16;

    //    /// <summary>
    //    ///   FIFO Status Register
    //    /// </summary>
    //    public const byte FIFO_STATUS = 0x17;

    //    /// <summary>
    //    ///   Enable dynamic payload length
    //    /// </summary>
    //    public const byte DYNPD = 0x1C;

    //    /// <summary>
    //    ///   Feature Register
    //    /// </summary>
    //    public const byte FEATURE = 0x1D;
    //}
}
